import tkinter as tk
import random

def generate_random_color():
    """生成随机颜色"""
    return f'#{random.randint(0, 255):02x}{random.randint(0, 255):02x}{random.randint(0, 255):02x}'

class ColorGridApp:
    def __init__(self, root):
        self.root = root
        self.root.title("四色窗口")
        self.root.geometry("400x400")
        
        # 创建4个区域
        self.create_color_grid()
        
    def create_color_grid(self):
        """创建4个颜色区域"""
        for i in range(2):
            for j in range(2):
                frame = tk.Frame(self.root, bg=generate_random_color())
                frame.grid(row=i, column=j, sticky="nsew", padx=5, pady=5)
                
        # 设置网格权重使区域均匀分布
        for i in range(2):
            self.root.grid_rowconfigure(i, weight=1)
            self.root.grid_columnconfigure(i, weight=1)

if __name__ == "__main__":
    root = tk.Tk()
    app = ColorGridApp(root)
    root.mainloop()
